#ifndef PROCESS_DEPTH_DATA_
#define PROCESS_DEPTH_DATA_

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fstream>
#include <errno.h>
#include <math.h>
#include <algorithm>
#include <opencv2/opencv.hpp>
#include <OpenNI.h>

#define SAMPLE_READ_WAIT_TIMEOUT 2000 //2000ms
#define Display_Mode        1   //测试图像显示模式
#define X_ZONE_NUM          32 //X轴划分区间的个数, 14
#define Y_ZONE_NUM          3 //Y轴划分区间的个数,
#define MAX_DETECT_PACK     X_ZONE_NUM * Y_ZONE_NUM //最大检测障碍物信息组数
#define WARN_LIMIT          1000    //能否通行的深度值界限。单位mm,范围在500~4500之间
#define X_DIVIDE            2   //x坐标抽样值(设定抽样值能节省时间，抽样值对全体有效)
#define Y_DIVIDE            2   //y坐标抽样值

using namespace std;
using namespace cv;
using namespace openni;

typedef struct depth_info_pack_type {
    float min_depth;
    float x_distance;
} depth_info_pack;

// 深度摄像头内参结构
struct CAMERA_INTRINSIC_PARAMETERS
{
    double cx = 325;
	double cy = 197;
	double fx = 476.9;
	double fy = 476.9;
	double scale = 1;
};

typedef struct depth_info_pack_mix_type
{
    depth_info_pack info_pack[MAX_DETECT_PACK];
} depth_info_mix;

class ProcessData
{
public:
    ProcessData();
    ~ProcessData();

    int process_depth_data(Mat &depth);
    void get_threshold_mask(Mat &src, Mat& thr, int thr_min, int thr_max);
    int filer_noise_test(Mat &src, int element_size, double val_prop);
    bool fall_down_obj(Mat &src, int element_size, double val_prop);
    bool ward_cam_obj(Mat &dep_src, double inval_pre);
	bool point_angle_trans(cv::Mat& src, int angle, int height, int height_max);
    cv::Mat gray_to_color(Mat &gray);
    void get_xrange(int xindex, int *x1, int *x2);
	void get_yrange(int yindex, int *y1, int *y2);

#if 1
    int start_process_orbbec(cv::Mat &depth_mat);
    int open_device_orbbec();
    int close_device_orbbec();
    void get_camera_params_orbbec();
#endif
private:
#if 1
    openni::Device device;
    VideoStream depth;
    VideoFrameRef frame;
	cv::Mat depth_view;
    openni::Status stat_;

#endif

    depth_info_mix mix_pack;
	CAMERA_INTRINSIC_PARAMETERS cam_para;
    int frame_width = 640;
    int frame_height = 400;
};


#endif